package 常用api;

import java.util.*;

public class Main {
    public static void main(String[] args) {
        List<String> names = new ArrayList<>();
        names.add("周杰伦");
        names.add("林俊杰");
        names.add("薛之谦");
        names.add("李荣浩");
        //addAll  批量添加元素
        Collections.addAll(names,"周杰伦","林俊杰","薛之谦","李荣浩");
        System.out.println(names);
        //shuffle  打乱集合顺序
        Collections.shuffle(names);
        System.out.println(names);

        List<Apple> apples = new ArrayList<>();
        apples.add(new Apple("红富士","红",13,15));
        apples.add(new Apple("蓝富士","蓝",15,16));
        apples.add(new Apple("蓝富士","蓝",14,14));
        Collections.sort(apples);//Apple类已经实现了Comparable功能 sort知道该怎么排
        System.out.println(apples);
        //sort方法自带比较器对象
        Collections.sort(apples,(o1, o2) -> Double.compare(o1.getPrice(),o2.getPrice()));
        System.out.println(apples);
    }
}
